Project 1: Quantum Random Number Generator
Description
A Quantum Random Number Generator (QRNG) leverages the principles of quantum mechanics, specifically superposition, to generate truly random numbers. Unlike classical pseudo-random number generators that rely on deterministic algorithms, QRNGs produce numbers that are fundamentally unpredictable.
Objectives
- Understand and implement the concept of superposition using a Hadamard gate.
- Create a quantum circuit that generates a random bit (0 or 1).
- Extend the circuit to generate a sequence of random bits to form a random number.
- Test the randomness of the generated numbers.
Implementation Details
- Framework: Use a quantum computing framework like Qiskit (Python) or Cirq.
- Circuit for a single random bit:
- Initialize a single qubit in the state $|0\rangle$.
- Apply a Hadamard gate to the qubit to put it in a superposition of $|0\rangle$ and $|1\rangle$.
- Measure the qubit. The outcome will be 0 or 1 with equal probability.
- Circuit for a random number:
- Repeat the single-bit process for a desired number of bits.
- Concatenate the bits to form a random number.
- Code Example (Qiskit):
from qiskit import QuantumCircuit, execute, Aer
def generate_random_bit():
# Create a quantum circuit with one qubit and one classical bit
circuit = QuantumCircuit(1, 1)
# Apply a Hadamard gate to the qubit
circuit.h(0)
# Measure the qubit
circuit.measure(0, 0)
# Execute the circuit on a simulator
backend = Aer.get_backend('qasm_simulator')
job = execute(circuit, backend, shots=1)
result = job.result()
counts = result.get_counts(circuit)
# Return the random bit
return int(list(counts.keys())[0])
# Generate a 4-bit random number
random_number = ""
for _ in range(4):
random_number += str(generate_random_bit())
print(f"Random number: {random_number}")